<?php

class textmoduleComponents extends sfComponents
{
    public function executeBacklink()
    {
        $text_module = TextModule::getById((int)$this->getRequestParameter('id', 0));
        $this->tree = null;

        if( $text_module->getId() )
        {
            $c = new Criteria();
            $c->add(TreePeer::OBJ_TYPE, MyConstants::TYPE_TEXTMODULE);
            $c->add(TreePeer::OBJ_ID, $text_module->getId());
            $this->tree = TreePeer::doSelectOne($c);
        }
    }

    public function executeText_layout_id()
    {
        $c = new Criteria();
        $this->arLayouts = TextLayoutPeer::doSelect($c);
    }

    public function executeGallery_list()
    {
        $c = new Criteria();
        $c->add(FilesPeer::OBJ_ID, $this->text_module->getId());
        $c->add(FilesPeer::OBJ_TYPE, MyConstants::TYPE_TEXTMODULE);
        $c->addDescendingOrderByColumn(FilesPeer::PRIORITY);
        $this->arFiles = FilesPeer::doSelect($c);
        $this->totalFiles = count($this->arFiles);
    }

	public function executePath()
	{
	    $this->arModules = MyConstants::getModuleTypeList();
		if( $this->getRequestParameter('id') )
		{
			$this->textModule = TextmodulePeer::retrieveByPk($this->getRequestParameter('id'));
			$c = new Criteria();
			$c->add(TreePeer::OBJ_ID, $this->textModule->getId());
			$c->add(TreePeer::OBJ_TYPE, MyConstants::TYPE_TEXTMODULE);
			$obj = TreePeer::doSelectOne($c);
			if( $obj ) 
			{
			    $this->arParents = Tree::getBranchById($obj->getId(), $this->getUser()->getCulture());
			}
		}
	}
}